package com.example.demo.poc.domain;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONPath;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.internal.JsonContext;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

import javax.xml.crypto.Data;
import java.io.File;
import java.io.IOException;
import java.util.List;

public class StrategyExchanger {

    public static final String DS_PATH = "$.datasets[*]";
    public static final String DS_PROP_PATH = "$.datasets[*].dataset_properties[*]";


    public List<DataSetConfig> toCIMDataSetConfig(){
        return null;
    }

    public List<DataSetConfig> readJsonStrategyConfig(String json){

        if(StringUtils.isBlank(json)){
            return null;
        }
        JsonContext cxt = (JsonContext) JsonPath.parse(json);
        String o = cxt.read(DS_PATH).toString();

        List<DataSetConfig> datasets =JSON.parseArray(o, DataSetConfig.class);
        System.out.println(datasets);
        return datasets;



    }

    public List<DataSetConfig> readJsonStrategyConfig(File file,String charset) throws IOException {
        return readJsonStrategyConfig(FileUtils.readFileToString(file,charset));
//        return null;
    }

    public static void main(String[] args) {
        StrategyExchanger exchange = new StrategyExchanger();
        try {
            exchange.readJsonStrategyConfig(new File("C:\\Users\\shink\\OneDrive\\DI\\design\\doc\\strategy.jsonc"),"UTF8");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
